package day15;

import java.util.*;

public class testlist01 {
    public static void main(String[] args) {
        List<String> list1=new ArrayList<>();
        list1.add("金");
        list1.add("木");
        list1.add("水");
        list1.add("火");
        list1.add("土");
        System.out.println(list1);
        List<String> list2=new ArrayList<>();
        list2.add("宫");
        list2.add("商");
        list2.add("角");
        list2.add("徵");
        list2.add("羽");
        System.out.println(list1.addAll(list2));
        System.out.println(list1.removeAll(list2));
        System.out.println(list1.get(0));
        System.out.println(list1.indexOf("火"));
        System.out.println(list1.lastIndexOf("土"));
//        System.out.println(list1.remove("火"));
//        System.out.println(list1);
        System.out.println(Arrays.toString(list1.toArray()));
        System.out.println(list1.get(2));//水
        System.out.println(list1.remove(2));
        System.out.println(list1);//[金, 木,  火, 土]
        list1.add(2,"水");
        System.out.println(list1);//[金, 木, 水, 火, 土]
        list1.addAll(0,list2);
        System.out.println(list1);
        System.out.println("四种迭代方式");
        System.out.println("for循环");
        for (int i = 0; i < list1.size(); i++) {
            System.out.print(list1.get(i)+",");
        }
        System.out.println("增强for循环");
        for (String n:list1){
            System.out.print(n+",");
        }
        System.out.println();
        System.out.println("iterator");
        Iterator<String> it1 = list1.iterator();
        while (it1.hasNext()){
            System.out.print(it1.next()+",");
        }
        System.out.println();
        System.out.println("listiterator");
        ListIterator<String> it2 = list1.listIterator();
        while (it2.hasNext()){
            System.out.print(it2.next()+",");
        }

    }
}
